const App = {
    mixins: [Save],//配置文件，路径/utils/mixins.js
    data() {
        return {
            childDataForm:[],
            fileUrl:'',
            showDialog:false
        };
    },
    mounted() {
        let ls_URL = window.location.href;
        this.action = getQueryObject(ls_URL, "Message_SerialNumber");   // 获取 action 参数
        this.getCategory();
    },
    methods: {
        getCategory() {
            // $.ajax({
            //     headers: requestHeaders(),
            //     url: `${mh}/generalBusiness/generalQueryForObtainingTrees`,
            //     type: "GET",
            //     data: {
            //         TableName:'comments',
            //         NodeCode:this.action
            //     },
            //     success: (data) => {
            //         this.treeData = data; // 直接使用 this
            //     },
            //     complete: (XMLHttpRequest) => {
            //         requestPretreatment(XMLHttpRequest)
            //     },
            //     dataType: "json",
            // });
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'message_board_attachment',
                    Condition: "Message_SerialNumber='" + this.action + "' AND Row_Status='0'",
                },
                success: (data) => {
                    this.childDataForm = data;
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryBySQLSerialNumber`,
                method: "post",
                data: {
                    SQLSerialNumber: 't_message_board',
                    Condition: window.btoa(unescape(encodeURIComponent("%%,%%"))),
                    ExtensionCondition:  window.btoa(unescape(encodeURIComponent(`AND message_board.Message_SerialNumber = '${this.action}'`))),
                },
                success: (data) => {
                    this.dataForm = data[0];
                    console.log(data[0]);
                }, 
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                }
            })
        },
        preview(row) {
            
            this.fileUrl = photo + row.Attachment_Path;
            this.showDialog = true;
        },
        async download(row) {
            // if (row.Attachment_Path) {
            //     window.location.href = photo + row.Attachment_Path;
            // }
            let apiUrl = photo + row.Attachment_Path;
            let fileName = apiUrl.split('/').pop();
            
            try {
                const response = await fetch(apiUrl);
                const blob = await response.blob();
                const url = window.URL.createObjectURL(blob);
                
                const a = document.createElement('a');
                a.href = url;
                a.download = fileName || 'download';
                document.body.appendChild(a);
                a.click();
                
                // 清理
                setTimeout(() => {
                    document.body.removeChild(a);
                    window.URL.revokeObjectURL(url);
                }, 100);
            } catch (error) {
                console.error('下载失败:', error);
            }
        },
    },
};
const { createApp, ref } = Vue;
const app = createApp(App);
app.use(ElementPlus,{locale: zhCn});
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
app.component('yl-upload', ylUpload);
app.component('yl-text-editor', ylTextEditor);
app.component('yl-online-preview', ylOnlinePreview);
const ElMessage = ElementPlus.ElMessage;
app.mount("#app");
